package List;

public class DeleteListNode {
    public ListNode removeElements(ListNode head, int val){
        if (head == null)
            return head;
        ListNode NewHead = new ListNode(-1,head);
        ListNode pre = NewHead;
        ListNode curIndex = head;
        while(curIndex != null){
            if(curIndex.val == val){
                pre.next = curIndex.next;
                curIndex = curIndex.next;
            }else{
                pre = curIndex;
                curIndex = curIndex.next;
            }
        }
        return NewHead.next;

    }
}
